package com.sh.weblogspringboot.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * EnableAsync注解用于启用 Spring 的异步特性。ThreadPoolTaskExecutor 用于创建一个线程池，
 * 具体根据实际的业务场景来调整核心线程数、最大线程数、队列容量等参数。
 *
 * @author songHai
 * @Classname ThreadPoolTaskExecutor
 * @Description
 * @Date 2025/4/13 11:34
 */
@Configuration
@EnableAsync
public class ThreadPoolConfig {

    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 核心线程数
        executor.setCorePoolSize(10);
        // 最大线程数
        executor.setMaxPoolSize(20);
        // 队列容量
        executor.setQueueCapacity(100);
        executor.setThreadNamePrefix("Weblog-ThreadPool-");
        executor.initialize();
        return executor;
    }
}
